<template>
  <div ref="target" class="home-new">
    <HomePannel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
      <!-- name=right的插槽 -->
      <template #right>
        <XtxMore path="/" />
      </template>
      <!-- name=default的默认插槽 -->
      <!-- 面板内容 -->
      <Transition name="fade">
        <ul class="goods-list" v-if="goods.length">
          <li v-for="item in goods" :key="item.id">
            <RouterLink :to="`/product/${item.id}`">
              <!-- <img :src="item.picture" alt=""> -->
              <img v-lazyload="item.picture" alt="">
              <p class="name ellipsis">{{ item.name }}</p>
              <p class="price">&yen;{{ item.price }}</p>
            </RouterLink>
          </li>
        </ul>
        <HomeSkeleton bg="#f0f9f4" v-else />
      </Transition>
    </HomePannel>
  </div>
</template>
<script>
import HomePannel from './home-pannel'
import { findNew } from '@/api/home'
import HomeSkeleton from './home-skeleton'
import { useLazyData } from '@/hooks'
export default {
  name: 'HomeNew',
  components: { HomePannel, HomeSkeleton },
  setup() {
    const { target, result } = useLazyData(findNew)
    return { target, goods: result }
  }
}
</script>
<style scoped lang="less">
// 骨架离开，组件进入动画效果
.fade {
  &-leave {
    &-active {
      position: absolute;
      width: 100%;
      transition: opacity .5s .2s;
      z-index: 1;
    }

    &-to {
      opacity: 0;
    }
  }
}

.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;

  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    // 使用mixinLess中的函数
    .hoverShadow();

    img {
      width: 306px;
      height: 306px;
    }

    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }

    .price {
      color: @priceColor;
    }
  }
}
</style>